package com.phgame.newsmth.adapter;

import java.util.ArrayList;
import java.util.List;

import com.example.android.bitmapfun.util.ImageWorker;
import com.phgame.newsmth.R;
import com.phgame.newsmth.ui.BaseActivity;
import com.phgame.newsmth.ui.MyApplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class PhotoAdapter extends BaseAdapter {

	class ViewHolder{
		ImageView image;
		TextView text;
	}
	View view;
	List<String> photourls ;
	private Context ctx;
	private ImageWorker worker;
	//ViewHolder holder;
	public PhotoAdapter(Context ctx){
		this.ctx = ctx;
		worker = ((MyApplication)ctx.getApplicationContext()).getImageWorker();
		worker.addImageCache(((BaseActivity) ctx).getSupportFragmentManager(), 
				((MyApplication)ctx.getApplicationContext()).getImageCacheParams());
		
		photourls = new ArrayList<String>();
	}
	@Override
	public int getCount() {
		
		return photourls.size();
	}

	@Override
	public Object getItem(int position) {
		
		return photourls.get(position);
	}

	@Override
	public long getItemId(int position) {
		
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder  holder;
		if(convertView == null){
			LayoutInflater mInflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = mInflater.inflate(R.layout.photo_grid_single_view, null);
			holder = new ViewHolder();
			holder.image = (ImageView) convertView.findViewById(R.id.gridimage);
			holder.text = (TextView) convertView.findViewById(R.id.gridtxt);
			convertView.setTag(holder);
			
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		return convertView;
	}

}
